<template>
<!-- 用到了 -->

  <div style="width: 100%; height: 100vh; overflow: hidden" :style="bg">
    <div style="width: 400px; margin: 100px auto">
      <div style="font-size: 30px; text-align: center; padding: 30px 0">GCU调查问卷系统欢迎注册</div>
      <el-form ref="form" :model="form" size="normal" :rules="rules">
        <el-form-item prop="userAccount">
          <el-input prefix-icon="el-icon-user-solid" v-model="form.userAccount" placeholder="请输入账号"></el-input>
        </el-form-item>
        <el-form-item prop="passWord">
          <el-input prefix-icon="el-icon-lock" v-model="form.passWord" show-password placeholder="请输入密码"></el-input>
        </el-form-item>
        <el-form-item prop="confirm">
          <el-input prefix-icon="el-icon-lock" v-model="form.confirm" show-password placeholder="请再次输入密码"></el-input>
        </el-form-item>
        <el-form-item prop="root" visibility="hidden" v-if="false">
          <el-input prefix-icon="el-icon-lock" v-model="form.root" show-password placeholder="权限"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button style="width: 100%" type="primary" @click="register">注册</el-button>
          <el-button type="text" @click="$router.push('/login')">《-返回登录  </el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import request from "@/utils/request";
import axios from 'axios'

export default {
  name: "Register",
  data() {
    return {
      form: {},
      rules: {
        userAccount: [
          {required: true, message: '请输入用户名', trigger: 'blur'},
        ],
        passWord: [
          {required: true, message: '请输入密码', trigger: 'blur'},
        ],
        confirm: [
          {required: true, message: '请确认密码', trigger: 'blur'},
        ],
      },
       bg: {
        backgroundImage: "url(" + require("@/assets/33.jpg") + ")",
        backgroundRepeat: "no-repeat",
        backgroundSize: "100% 100%"
      },
    }
  },
  methods: {
    register() {

      if (this.form.passWord !== this.form.confirm) {
        this.$message({
          type: "error",
          message: '2次密码输入不一致！'
        })
        return
      }

      this.$refs['form'].validate((valid) => {
        if (valid) {
          // request.post("/user/register", this.form).then(res => {
          //   if (res.code === '0') {
          //     this.$message({
          //       type: "success",
          //       message: "注册成功"
          //     })
          //     this.$router.push("/login")  //登录成功之后进行页面的跳转，跳转到主页
          //   } else {
          //     this.$message({
          //       type: "error",
          //       message: res.msg
          //     })
          //   }
          // })
          this.form.root=2
          console.log(this.form)
          axios({
         method:"POST",
        //  url:"http://uchiha.vip:5000/User/",
         url:"/User/",

         data:this.form
         }).then(res=>{
        console.log(res)
         this.$message({
              type: "success",
              message: "注册成功"
          })
          this.$router.push("/login") 
        //  this.load() // 刷新表格的数据
        // this.dialogVisible = false  // 关闭弹窗
      })

        }
      })
    }
  }
}
</script>

<style scoped>

</style>
